<?
//echo '<pre>';
//print_r($data);
//$store_title = array('title'=>$data['res'][result][0][store],'store_id'=>$data['res'][result][0][store_id]);
$store_title = $data['store_info'];

$bitmap = array(
	'client_blocked'=>array(0=>'Active',1=>'Blocked',2=>'Paused',3=>'Expired',4=>'Active'),
	'currencies'=>array('USD'=>'US$','CAD'=>'CA$','AUD'=>'AU$','EUR'=>'&#8364','GBP'=>'&pound'),
	'order_status'=>array(0=>'Not Verified',128=>'Not Verified',256=>'Not Verified',512=>'Not Verified',16=>'OK',32=>'OK',2=>'Fraud',1=>'Refund',4=>'MBG',8=>'Charge-Back',64=>'Charge-Back',1024=>'Refund',''=>'-')
);

$curr_page = ($data['options']['offset'] ?  $data['options']['offset']/$data['options'][limit]+1 : 1);
$pages = ceil($data['res']['num_rows']/$data['options']['limit']);
$order_ids = array();

if($data['res']['num_rows']>0){
	$result_table = '<table class="master_tbl" width="100%"  border="0" cellspacing="0" cellpadding="0" id="affiliates">
		<tr><td colspan="10" height="2" bgcolor="#696969"></td></tr>
		<tr bgcolor="#DDE5E8">
		<td align="center" class="black"><strong>OrderID</strong></td>
		<td align="center" class="black"><strong>Date</strong><br/>mm/dd/yyyy</td>
		<td align="center" class="black"><strong>Affiliate</strong></td>
		<td align="center" class="black"><strong>Username</strong></td>
		<td align="center" class="black"><strong>Type</strong></td>
		<td align="center" class="black"><strong>Item</strong></td>
		<td align="center">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td style="text-align:center;border-right:0px;" bgcolor="#C6D5DC" colspan="3" class="black"><strong>Transaction</strong></td>
			  </tr>
			  <tr bgcolor="#DDE5E8">
				<td width=80 style="text-align:center;border-bottom:0px;border-right:0px;" class="black"><strong>Total</strong></td>
				<td width=80 style="text-align:center;border-bottom:0px;border-right:0px;" class="black"><strong>Wholesale</strong></td>
				<td width=60 style="text-align:center;border-bottom:0px;border-right:0px;" class="black"><strong>Status</strong></td>
			  </tr>
			</table>
		</td>
		<td align="center" class="black"><strong>Account<br/>Status</strong></td>
		<td align="center" class="black"><strong>Net<br/>Profit</strong></td>
		<td align="center" class="black"><strong>Issued</strong><br/>mm/dd/yyyy</td>
		</tr><tr><td colspan="10" height="2" bgcolor="#696969"></td></tr>';
	foreach($data['res']['result'] as $k => $row){
		if($totals[($row[payment_currency_])]){
			$totals[($row[payment_currency_])]['amount_total'] = bcadd($totals[($row[payment_currency_])]['amount_total'],$row['amount_total'],2);
			$totals[($row[payment_currency_])]['amount_wholesale'] = bcadd($totals[($row[payment_currency_])]['amount_wholesale'],$row['amount_wholesale'],2);
			$totals[($row[payment_currency_])]['amount_referer'] = bcadd($totals[($row[payment_currency_])]['amount_referer'],$row['amount_referer'],2);
			if(!in_array($row[order_id],$order_ids)){
				$totals[($row[payment_currency_])]['count'] += 1;
				$order_ids[] = $row[order_id];
			}
		}else{
			$totals[($row[payment_currency_])]['amount_total'] = $row['amount_total'];
			$totals[($row[payment_currency_])]['amount_wholesale'] = $row['amount_wholesale'];
			$totals[($row[payment_currency_])]['amount_referer'] = $row['amount_referer'];
			if(!in_array($row[order_id],$order_ids)){
				$totals[($row[payment_currency_])]['count'] = 1;
				$order_ids[] = $row[order_id];
			}
		}

	if(in_array($row['order_status'],array(1,2,4,1024))){
		$style = 'bgcolor=#FDC7F9';
                if($row['sale_type']=='reversal'){
			$style = 'bgcolor=#A15C9C';
		}
	}elseif(in_array($row['order_status'],array(8,64))){
		$style = 'bgcolor=#FECA50';
	}else{
		if(in_array($row['client_blocked'],array(1,3))){
			$style = 'bgcolor=#9EDAFC';
		}else{
			if($flag){
                                if($tmp_order_id != $row[order_id]){
                                        $tmp_order_id = $row[order_id];
					unset($flag);
					$style = 'bgcolor=#EBEBEB';
				}
			}else{
                                if($tmp_order_id != $row[order_id]){
                                        $tmp_order_id = $row[order_id];
					$flag = 1;
					$style = 'bgcolor=#FFFFFF';
				}
			}
		}
	}
		$result_table .= "<tr $style>
		<td nowrap style='padding-left:5px;' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='orange2'>$row[order_id]</td>
		<td nowrap height='16' align='center' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".date('m/d/Y',strtotime($row[order_date]))."</td>
		<td nowrap style='padding-left:10px;' ".($style == 'bgcolor=#A15C9C' ?  "class='white_blue'" : "")." class='blue'>$row[reseller]</td>
		<td nowrap style='padding-left:10px;' ".($style == 'bgcolor=#A15C9C' ?  "class='orange'" : "")." class='orange2'>".($row[username] ? $row[username] : '-')."</td>
		<td nowrap align='center' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>$row[sale_type]</td>
		<td nowrap align='center' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".($row[product_type] ? $row[product_type] : '-')."</td>
		<td>
			<table  width='100%' border='0' cellspacing='0' cellpadding='0'>
				<tr>
					<td nowrap width=75 align=right style='padding-right:5px;border-bottom:0px;border-right:0px;' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".($bitmap[currencies][($row[payment_currency_])])." $row[amount_total]</td>
					<td nowrap width=75 align=right style='padding-right:5px;border-bottom:0px;border-right:0px;' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".($bitmap[currencies][($row[payment_currency_])])." $row[amount_wholesale]</td>
					<td nowrap width=55 align=center style='padding-left:5px;border-bottom:0px;border-right:0px;' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".($row[sale_type]!='reversal' ? $bitmap['order_status'][($row[order_status])] : ($row[order_status]=='1024' ? 'P.Refund' : 'F.Refund'))."</td>
				</tr>
			</table>
		</td>
		<td nowrap align='center' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".(is_numeric($row[client_blocked]) ? $bitmap['client_blocked'][($row[client_blocked])] : '-')."</td>
		<td nowrap style='padding-right:5px;' align='right' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".$bitmap[currencies]['USD']." $row[amount_referer]</td>
		<td nowrap align='center' ".($style == 'bgcolor=#A15C9C' ?  "class='white-normal'" : "")." class='black'>".($row[payed_referer] ? date('m/d/Y',strtotime($row[payed_referer])) : '-')."</td>
		</tr>";
	}

	$result_table .= '</tr><tr><td height="2" colspan="10" bgcolor="#696969"></td></tr>';
	foreach($totals as $currency=>$row){
		$result_table .= "<tr bgcolor='#0660B6'>
			<td height=16 class='white' style='padding-left:10px;border-bottom:0px;border-right:0px;'>$row[count]</td>
			<td colspan=5 class='white' style='border-bottom:0px;border-right:0px;'>SUB-TOTALS:</td>
			<td style='border-bottom:0px;border-right:0px;'>
				<table width='100%' border='0' cellspacing='0' cellpadding='0'>
					<tr>
						<td width='75' align=right style='padding-right:5px;border-bottom:0px;border-right:0px;' class='white'>".$bitmap[currencies][$currency]." ".number_format($row[amount_total], 2, '.', ',')."</td>
						<td width='75' align=right style='padding-right:5px;border-bottom:0px;border-right:0px;' class='white'>".$bitmap[currencies][$currency]." ".number_format($row[amount_wholesale], 2, '.', ',')."</td>
						<td width='60' style='border-bottom:0px;border-right:0px;' class='white'></td>
					</tr>
				</table>
			</td>
			<td style='border-bottom:0px;border-right:0px;' class='white'></td>
			<td align=right style='padding-right:5px;border-bottom:0px;border-right:0px;' class='white'>".$bitmap[currencies][USD]." ".number_format($row[amount_referer], 2, '.', ',')."</td>
			<td style='border-bottom:0px;' class='white'></td>
			</tr><tr><td height='1' colspan='10' bgcolor='#EBEBEB'></td></tr>";
	}
	$result_table .= '</tr><tr><td height="2" colspan="10" bgcolor="#696969"></td></tr></table><br>';

	foreach(array('all','ok','ref','cb') as $k=>$v){
		$var_string = "totals_$v";
		foreach($data[res1][$v][result] as $kk=>$vv){
			$totals2[($vv[payment_currency_])][$v] = $vv;
		}
	}

//	echo '<pre>';
//	print_r($totals2);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Statistics: Affiliates</title>
<link href="sales/styles.css" rel="stylesheet" type="text/css">
<SCRIPT language="javascript" src="sales/tooltip.js"></SCRIPT>
<script>
function page(val){
	var offset = <? echo($data['options']['offset'] ? $data['options']['offset'] : 0);?>;
	var limit = <?echo($data['options']['limit'] ? $data['options']['limit'] : 0);?>;
	var rows = <?echo($data['res']['num_rows'] ? $data['res']['num_rows'] : 0);?>;
	var page_num = document.daForm.elements['goto_page'].value;

	if(val=='prev'){
		if(offset!=0){
			document.daForm.elements['options[offset]'].value = offset-limit;
			document.daForm.submit();
		}
	}
	if(val=='next'){
		if(offset+limit<rows){
			document.daForm.elements['options[offset]'].value = offset+limit;
			document.daForm.submit();
		}
	}

	if(val=='goto_page'){
		if(valid_page_num(page_num)){
			document.daForm.elements['options[offset]'].value = limit * (page_num-1);
			document.daForm.submit();
		}else{
			alert('Invalid Page Number');
		}
	}
}

function valid_page_num(page_num){
	var pages = <?echo $pages;?>;
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < page_num.length && IsNumber == true; i++) {
		Char = page_num.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	if(IsNumber && page_num>=1 && page_num<=pages){
		return true;
	}else{
		return false;
	}
}
</script>
</head>

<body>
<form action="" method="POST" name="daForm">
<table width="879" border="0" cellspacing="0" cellpadding="0"><tr><td>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="18" width="18"><img src="sales/images/stats_affiliates_icon.jpg" width="18" height="18" border="0"/></td>
    <td height="18" width="690" class="bluetext" valign="bottom" style="padding-bottom:3px; ">AFFILIATES STATISTICS:</td>
    <td height="18" align="right"><a href="#"><img src="sales/images/help.gif" alt="Online Help" height="15" border="0"></a><!-- <a href="#"><img src="sales/images/v_tutorials.gif" alt="Video Tutorials" border="0"></a> <a href="#"><img src="sales/images/faq.gif" alt="Frequently Asked Questions" width="15" height="14" border="0"></a>--></td>
  </tr>
  <tr>
    <td height="10" colspan="3"></td>
  </tr>
</table>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td width="29">&nbsp;</td>
	<td width="147">
	<table width="150" border="0" cellspacing="0" cellpadding="0">
		<!-- Transaction Status -->
	  <tr>
		<td colspan="2" class="black">Transaction Status:</td>
	  </tr>
	  <tr bgcolor="#F6D3B7">
		<td height="18" width="23"><input type="checkbox" name="params[order_status][1]" <?if($data['params']['order_status'][1]) echo 'checked';?>></td>
		<td width="151" bgcolor="#F6D3B7" class="black"><strong>ALL</strong></td>
	  </tr>
	  <tr bgcolor="#EBEBEC">
		<td height="18" width="23"><input type="checkbox" name="params[order_status][2]" <?if($data['params']['order_status'][2] and !$data['params']['order_status'][1]) echo 'checked';?> onClick="if(document.daForm.elements['params[order_status][1]'].checked==true && this.checked==true) document.daForm.elements['params[order_status][1]'].checked=false;"></td>
		<td class="black">OK</td>
	  </tr>
	  <tr bgcolor="#EBEBEC">
		<td height="18" width="23"><input type="checkbox" name="params[order_status][3]" <?if($data['params']['order_status'][3] and !$data['params']['order_status'][1]) echo 'checked';?> onClick="if(document.daForm.elements['params[order_status][1]'].checked==true && this.checked==true) document.daForm.elements['params[order_status][1]'].checked=false;"></td>
		<td class="black">REFUND</td>
	  </tr>
	  <tr bgcolor="#EBEBEC">
		<td height="18" width="23"><input type="checkbox" name="params[order_status][4]" <?if($data['params']['order_status'][4] and !$data['params']['order_status'][1]) echo 'checked';?> onClick="if(document.daForm.elements['params[order_status][1]'].checked==true && this.checked==true) document.daForm.elements['params[order_status][1]'].checked=false;"></td>
		<td class="black">CHARGE-BACK</td>
	  </tr>
	  <!-- END Of Transaction Status -->
	  </table>
	<td width="29">&nbsp;</td>
    <td width="130">

	<!-- DATE SCRIPT -->

	<script src="sales/calendar.js"></script>
	<table width="120" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td colspan="2" class="black">Start Date Period:</td>
	  </tr>
	  <tr>
		<td width="88"><input id="sdate" name="sdate" <? if($data['sdate']) echo "value=$data[sdate]";?> title="Start date" class="black" style="width: 80px; height: 16px; border: 1px solid #89B4CC; font-weight:bold; color:#B51235; padding-left:9px;"></td>
		<td width="32" align="left"><a href="#" title="Click to choose start date" onclick="popUpCalendar(daForm, daForm.sdate, daForm.sdate, 'yyyy-mm-dd');"><img src="sales/images/calendar.gif" alt="Set Start Date" width="18" height="14" border="0"/></a></td>
	  </tr>
	  <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	  </tr>
	  <tr>
		<td class="black" colspan="2">End Date Period:</td>
	  </tr>
	  <tr>
		<td><input id="edate" name="edate" <? if($data['edate']) echo "value=$data[edate]";?> title="End date" class="black" style="width: 80px; height: 16px; border: 1px solid #89B4CC; font-weight:bold; color:#B51235; padding-left:9px;"></td>
		<td align="left"><a href="#" title="Click to choose end date" onclick="popUpCalendar(daForm, daForm.edate, daForm.edate, 'yyyy-mm-dd');"><img src="sales/images/calendar.gif" alt="Set End Date" width="18" height="14" border="0"/></a></td>
	  </tr>
	  <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	  </tr>
	</table>
</form>

	<!--  END DATE SCRIPT -->


	</td>
    <td width="29"></td>
    <td width="210">

	<table width="190px"  border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td colspan="2" class="black">Your Store Name:</td>
		  </tr>
		  <tr>
			<td>
				<select name="params[store_id]" class="silver2" style="width:100%; border:1px solid #7B9EBD;" size="7">
						<option selected value="" ><? echo $store_title['title']; ?></option>
				</select>
			</td>
		  </tr>
	</table>

	</td>
    <td width="29">&nbsp;</td>
    <td width="216">

	<!-- CURRENCIES TABLE -->
	<table width="190px"  border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td colspan="2" class="black">Your currencies:</td>
		  </tr>
		  <tr>
			<td>
				<select name="params[payment_currency]" class="silver2" style="width:190px; border:1px solid #7B9EBD;" size="7">
						<option selected value="ALL" <?if(!$data[params][payment_currency]) echo 'selected';?>>ALL CURRENCIES (View All)</option>
						<option value="" >------------------------------------</option>
						<option value="USD" <?if($data[params][payment_currency]=='USD') echo 'selected';?>>USD (United States Dollar)</option>
						<option value="GBP" <?if($data[params][payment_currency]=='GBP') echo 'selected';?>>GBP (Great Britain Pound)</option>
						<option value="EUR" <?if($data[params][payment_currency]=='EUR') echo 'selected';?>>EUR (Euro)</option>
						<option value="CAD" <?if($data[params][payment_currency]=='CAD') echo 'selected';?>>CAD (Canadian Dollar)</option>
						<option value="AUD" <?if($data[params][payment_currency]=='AUD') echo 'selected';?>>AUD (Australian Dollar)</option>
<!--					<option value="BGL" >BGL (Bulgarian Lev)</option> -->
				</select>
			</td>
		  </tr>
		</table>
	<!-- END OF CURRENCIES TABLE -->

	</td>
  </tr>
  <tr>
    <td background="sales/images/horizontal_dots_stats.gif" height="18" colspan="9"></td>
  </tr>

</table>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
<tr>
    <td width="199" valign="middle" class="black">Results per page:
		<select class="blackdown" style="width:70px; height:16px;" name="options[limit]">
		<!--<option value="1000000">ALL</option>-->
		<option value="10" <?if($data['options']['limit']=='10') echo 'selected';?>>10</option>
		<option value="20" <?if($data['options']['limit']=='30') echo 'selected';?>>20</option>
		<option value="50" <?if($data['options']['limit']=='50') echo 'selected';?>>50</option>
		<option value="100" <?if($data['options']['limit']=='100') echo 'selected';?>>100</option>
		</select>
</td>
    <td width="15" valign="middle">&nbsp;</td>
    <td width="214">
    <input type=hidden name='options[offset]'>
    <input style="width:102px; background-image:url(sales/images/view_stats_btn.jpg); border:0px; padding-left:12px;" type="submit" class="blackdown" value="View Report">
    </td>
    <td width="451">&nbsp;</td>
  </tr>
    <tr>
    <td height="29" colspan="10"></td>
  </tr>
</table>


<!-- SEARCH RESULTS TABLE -->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	  <tr>
		<td width="9"><img src="sales/images/arrow_red.jpg" width="9" height="9"></td>
		<td style="padding-left: 5px;" class="black"><strong>Search Results from <? echo($data['options']['offset'] + 1);?> to <?echo(($data['options']['offset'] + $data['options']['limit'])>$data['res']['num_rows'] ? $data['res']['num_rows'] : ($data['options']['offset'] + $data['options']['limit']));?> for <span class="red"><? echo $store_title['title']; ?></span>:</strong>&nbsp;&nbsp;&nbsp; <span class="silver">[ from: </span><span class="red"><?echo ($data[sdate] ? date('M d, Y',strtotime($data['sdate'])) : date('M d, Y',strtotime($data['res']['result'][(count($data['res']['result'])-1)]['order_date'])));?></span><span class="silver"> to: </span><span class="red"><?echo ($data[edate] ? date('M d, Y',strtotime($data[edate])) : date('M d, Y',strtotime($data['res']['result']['0']['order_date'])));?></span><span class="silver"> ]</span></td>
		<td class="black" style="padding-left: 5px;padding-bottom: 3px;" align="right"><a href="#"><img src="sales/images/help.gif" alt="Online Help" height="15" border="0"></a><!--<a href="#"><img src="sales/images/v_tutorials.gif" alt="Video Tutorials" border="0"></a> <a href="#"><img src="sales/images/faq.gif" alt="Frequently Asked Questions" width="15" height="14" border="0"></a>--></td>
	  </tr>
</table>

<!-- SEARCH RESULTS TABLE -->
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td>
		<?
			if($data[res][num_rows]>0){
				echo $result_table;
			}else{
				$no_pages = 1;
				if($data['no_affiliates']){
					$no_result_text = 'You Do Not Have Affiliates Yet.';
				}else{
					$no_result_text = 'No Results Found.<br>Please have in mind that these statistics cover only commission payments made after 05 October 2005 and pending commission payments.';
				}
				echo "<center><p class='black'>$no_result_text</p></center>";
			}
		?>
		</td>
	</tr>
</table>
<!-- END OF SEARCH RESULTS TABLE -->

<!-- PAGE NUMBERS AREA -->
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="11" colspan="14"></td>
  </tr>
  <tr>
	<?
	if($no_pages != 1){?>
    <td height="21" width="21"><?if($curr_page==1) echo '<img src="sales/images/result_arrow_disabled_left.jpg" alt="View Previous Results Page" width="21" height="21" border="0" />'; else echo '<a href="javascript:page(\'prev\');"> <img src="sales/images/result_arrow_enabled_left.jpg" alt="View Previous Results Page" width="21" height="21" border="0" /></a>';?></td>
    <td width="180" class="black" style="padding-left:7px; ">Results page: <span class="red style2"><strong><? echo $curr_page; ?></strong></span> of <span class="black style2"><strong><? echo $pages; ?></strong></span></td>
    <td width="21"><?if($curr_page==$pages) echo '<img src="sales/images/result_arrow_disabled_right.jpg" alt="View Next Results Page" border="0" />'; else echo '<a href="javascript:page(\'next\');"><img src="sales/images/result_arrow_enabled_right.jpg" alt="View Next Results Page" border="0" /></a>'; ?></td>
    <td width="23"></td>
    <td class="black" width="142" align="right" style="padding-right:7px; ">Go Directly to page: </td>
    <td width="40" align="left"><input name="goto_page" class="black" style="width:34px; height: 14px; padding-left:7px; border: 1px solid #89B4CC; font-weight:bold; color:#FD3E56;"></td>
    <td width="28" style="padding-left:7px; "><a href="javascript:page('goto_page');" ><img src="sales/images/go2page_arrow.jpg" alt="View Selected Page" border="0"></a></td>
	<?}else{ echo '<td width=455></td>'; }?>
    <td width="120"></td>
    <td width="21"><img src="sales/images/charge-back_lgnd.jpg" border="0"></td>
    <td width="95" class="black" style="padding-left:5px; ">Charge-Back</td>
    <td width="21"><img src="sales/images/refund_lgnd.jpg" border="0"></td>
    <td width="95" class="black" style="padding-left:5px; ">Refund</td>
    <td width="21"><img src="sales/images/blocked_lgnd.jpg" border="0"></td>
    <td width="95" class="black" style="padding-left:5px; ">Blocked</td>
  </tr>
  <tr>
    <td colspan="14" height="42"></td>
  </tr>
</table>
<!-- END OF PAGE NUMBERS AREA -->

<table width="879"  border="0" cellspacing="0" cellpadding="0">
<!-- TOTALS AREA -->
  <tr valign="top">
    <td width="307">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="9"><img src="sales/images/arrow_red.jpg" width="9" height="9"></td>
				<td style="padding-left: 5px;" class="black"><strong>AFFILIATES:</strong></td>
			  </tr>
		</table>
		<table width="100%" cellspacing="0" class="stats_tables">
          <tr bgcolor="#0660B6">
            <td style="border-right:1px solid white; padding-left:7px;" height="17" class="white">STORE</td>
            <td style="border-right:1px solid white;" align="center" class="white">AFFILIATES</td>
          </tr>
          <tr>
            <td height="17" class="black" style="padding-left:7px; "><strong><?=$store_title['title']?></strong></td>
            <td align="center" class="black"><strong><?=((count($data['reseller_id']) + $data[cpanel_affiliates_count]) ? (count($data['reseller_id'])+$data[cpanel_affiliates_count]):0)?></strong></td>
          </tr>
        </table>
	</td>
    <td width="10"></td>
    <td>
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="9"><img src="sales/images/arrow_red.jpg" width="9" height="9"></td>
				<td style="padding-left: 5px;" class="black"><strong>AFFILIATE SALES TOTALS:</strong></td>
			  </tr>
		</table>
<table width="100%" cellspacing="0" class="stats_tables">
	<tr bgcolor="#0660B6">
		<td height="17" width="94" style="border-right:1px solid white; padding-left:7px;" class="white">STORE</td>
		<td align="center" style="border-right:1px solid white;" class="white">SALES</td>
		<td align="center" style="border-right:1px solid white;" class="white">REFUND</td>
		<td align="center" style="border-right:1px solid white;" class="white">CHARGE-BACK</td>
		<td align="center" style="border-right:1px solid white;" class="white">NET REVENUE</td>
		<td align="center" class="white">NET PROFIT</td>
	</tr>
<?
if($totals2){
	foreach($totals2 as $curr=>$row){
		$bgcolor = ($bgcolor=="#FFFFFF" ? "#EBEBEB" : "#FFFFFF");
		echo "
			<tr bgcolor='$bgcolor'>
				<td height='17' class='black' align='center'><strong>$store_title[title]</strong></td>
				<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies'][$curr]." ".$row['all']['amount_total']."</td>
				<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies'][$curr]." ".($row['ref']['amount_total'] ? $row['ref']['amount_total'] : '0.00')."</td>
				<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies'][$curr]." ".($row['cb']['amount_total'] ? $row['cb']['amount_total'] : '0.00')."</td>
				<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies'][$curr]." ".($row['ok']['amount_wholesale'] ? $row['ok']['amount_wholesale'] : '0.00')."</td>
				<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." ".$row['ok']['amount_referer']."</td>
			</tr>
		";
	}
}else{
	echo "
		<tr>
			<td class='black' align='center'><strong>$store_title[title]</strong></td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
		</tr>
		<tr bgcolor='#EBEBEC'>
			<td class='black' align='center'><strong>$store_title[title]</strong></td>
			<td class='black' align='right' style='padding-right:5px;'>$".$bitmap['currencies']['GBP']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['GBP']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['GBP']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['GBP']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
		</tr>
		<tr>
			<td class='black' align='center'><strong>$store_title[title]</strong></td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['EUR']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['EUR']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['EUR']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['EUR']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
		</tr>
		<tr bgcolor='#EBEBEC'>
			<td class='black' align='center'><strong>$store_title[title]</strong></td>
			<td class='black' align='right' style='padding-right:5px;'>$".$bitmap['currencies']['CAD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['CAD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['CAD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['CAD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
		</tr>
		<tr bgcolor='#EBEBEC'>
			<td class='black' align='center'><strong>$store_title[title]</strong></td>
			<td class='black' align='right' style='padding-right:5px;'>$".$bitmap['currencies']['AUD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['AUD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['AUD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['AUD']." 0.00</td>
			<td class='black' align='right' style='padding-right:5px;'>".$bitmap['currencies']['USD']." 0.00</td>
		</tr>
	";
}
?>
	</table>
	</td>
  </tr>
  <tr>
    <td colspan="3" height="44">&nbsp;</td>
  </tr>
<!-- END OF TOTALS AREA -->
</table>




<!-- FAST JUMPS AREA -->
<!--
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="21"><img src="sales/images/fast_jump_icon.jpg" alt="Affiliates Fast Jumps Icon" width="21" height="21"></td>
    <td colspan="2" class="bluetext">AFFILIATES FAST JUMPS:</td>
  </tr>
  <tr>
    <td colspan="14" height="14"></td>
  </tr>
  <tr>
    <td height="18"></td>
    <td width="17"><img src="sales/images/fast_jumps_arrow.jpg" alt="Fast Jumps Arrow" width="16" height="15" border="0"></td>
    <td width="841" class="bluetext"><a href="#">Banners</a></td>
  </tr>
  <tr>
    <td height="18"></td>
    <td><img src="sales/images/fast_jumps_arrow.jpg" alt="Fast Jumps Arrow" width="16" height="15" border="0"></td>
    <td class="bluetext"><a href="#">Remote Forms</a></td>
  </tr>
  <tr>
    <td height="18">&nbsp;</td>
    <td><span class="black"><img src="sales/images/fast_jumps_arrow.jpg" alt="Fast Jumps Arrow" width="16" height="15" border="0"></span></td>
    <td class="bluetext"><a href="#">Terms</a></td>
  </tr>
  <tr>
    <td height="56" colspan="3"></td>
  </tr>
</table>
-->
<!-- END OF FAST JUMPS AREA -->

<!-- LEGEND AREA -->
<!--
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="21"><img src="sales/images/legend_info.jpg" alt="Legend"></td>
    <td colspan="2" class="bluetext">LEGEND:</td>
  </tr>
  <tr>
    <td colspan="14" height="14"></td>
  </tr>
  <tr>
    <td height="25"></td>
    <td width="23"><span class="black"><img src="sales/images/help.gif" alt="Online Help" width="16" height="15" border="0"></span></td>
    <td width="835" class="black">Online Help </td>
  </tr>
  <tr>
    <td height="25"></td>
    <td><span class="black"><img src="sales/images/v_tutorials.gif" alt="Video Tutorials" border="0"></span></td>
    <td class="black">Video Tutorials </td>
  </tr>
  <tr>
    <td height="25">&nbsp;</td>
    <td><span class="black"><img src="sales/images/faq.gif" alt="Frequently Asked Questions" width="15" height="14" border="0"></span></td>
    <td class="black">Frequently Asked Questions (FAQ) </td>
  </tr>
  <tr>
    <td height="56" colspan="3"></td>
  </tr>
</table>
-->
<!-- END OF LEGEND AREA -->
</td></tr></table>
</form>
</body>
</html>